/**
 *
 * Required 和Partial 和 ReadOnly
 */

type Partial<T> = {
  [P in keyof T]?: T[P];
};
interface ButtonProps {
  type: "button" | "submit" | "reset";
  text: string;
  disabled: boolean;
  onClick: () => void;
}

// ! 全部变成了可选
type parialProps = Partial<ButtonProps>;

let props: parialProps = {
  text: "登录",
};

interface Todo {
  title: string;
  completed: boolean;
  description: string;
  // orther unimportant
  other?: string;
  date?: string;
}

//! Required 和Partial相反 一次性全部变成必选选项的type高级类型
type Required<T> = {
  [P in keyof T]-?: T[P];
};

// 变成可选
type requiredTodo = Required<Todo>;

const todo1: requiredTodo = {
  title: "1",
  completed: false,
  description: "test",
  other: "",
  date: "2022-12-27",
};

//  ReadOnly 一次性全部变成可读选项的type高级类型
type ReadOnly<T> = {
  readonly [P in keyof T]: T[P];
};

type readTodo = ReadOnly<Todo>;

const todo2: requiredTodo = {
  title: "1",
  completed: false,
  description: "test",
  other: "",
  date: "2022-12-27",
};
todo2.completed = true ;// 属性只读,但是可以修改属性内容

console.log('todo2',todo2);

export {};
